﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;
using System.Collections;

namespace LinqToPowershell
{
    [Cmdlet("Test", "Generic")]
    public class GenericCmdletExample : Cmdlet
    {
        [Parameter(Mandatory = true, Position = 0)]
        public IEnumerable List { get; set; }

        protected override void ProcessRecord()
        {
            var typeArgs = GenericHelper.GetTypeArgs(List);
            if (typeArgs == null)
                return;

            typeArgs.Add(typeof(string));
            var dict = GenericHelper.CreateGeneric(typeof(Dictionary<,>), typeArgs) as IDictionary;

            foreach (var item in List)
            {
                dict.Add(item, item.ToString());
            }
            WriteObject(dict);
        }
    }
}
